Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

RecordsetToHTMLTable - Convert an ADO Recordset to a HTML table

Total Hit ( 5826)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' Create a HTML table from a recordset
'
' set the TableAttribs argument to a suitable value
'   (eg "BORDER=1") to modify the table's standard layout
' you should omit the NullValues argument if you want that null
'   values are displayed in empty cells
' set the ShowFieldNames to True to display field names in boldface
' set the IncludeWhiteSpace argument to True if you want to produce
'   a longer and less efficient (but more readable) output

Function RecordsetToHTMLTable(rs As ADODB.Recordset, _
  ByVal TableAttribs As String, Optional ByVal NullValues As String = _
  " ", Optional ByVal ShowFieldNames As Boolean, _
  Optional ByVal IncludeWhiteSpace As Boolean) As String
  Dim res As String
  Dim fld As ADODB.Field
  Dim tmp As String
  Dim lf As String, tb As String
  
  ' fill these variables only if spaces are to be kept
  If IncludeWhiteSpace Then
    lf = vbCrLf
    tb = vbTab
  End If
  
  ' prepare the <TABLE> tag
  res = "<TABLE " & TableAttribs & ">" & lf
  
  ' show field names, if required
  If ShowFieldNames Then
    res = res & tb & "<HEAD>" & lf
    For Each fld In rs.Fields
      res = res & tb & tb & "<TD><B>" & fld.Name & "</B></TD>" & lf
    Next
    res = res & tb & "</HEAD>" & lf
  End If

  ' get all the records in a semi-formatted string
  tmp = rs.GetString(, , "</TD>" & lf & tb & tb & "<TD>", _
    "</TD>" & lf & tb & "</TR>" & lf & tb & "<TR>" & lf & tb & tb & "<TD>", _
    NullValues)
  ' strip what has been appended to the last cell of the last row
  tmp = Left$(tmp, Len(tmp) - Len(lf & tb & "<TR>" & lf & tb & tb & "<TD>"))
  
  ' add opening tags to the first cell of the first row of the table
  ' and complete the table
  RecordsetToHTMLTable = res & tb & "<TR>" & lf & tb & tb & "<TD>" & tmp & lf _
    & "</TABLE>"
  
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.